package junit.com.cpi.cornpp.common.files;

import java.util.List;

import junit.framework.TestCase;

import com.cpi.cornpp.common.files.SAPComponentCornGrind;
import com.cpi.cornpp.common.files.exception.SAPComponentFileException;
/**
 * Corn Grind Test Case
 * @author Edgar Joao
 * @see TestCase
 */
public class SAPComponentCornGrindTest extends TestCase {

	private static final String FILE_NAME = "Grind.txt";
	private SAPComponentCornGrind sapComponentCornGrind = null;
	
	public SAPComponentCornGrindTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		sapComponentCornGrind = new SAPComponentCornGrind(FILE_NAME);
	}

	protected void tearDown() throws Exception {
		sapComponentCornGrind = null;
	}

	public void testParse() {
		List fileLines = null;
		List fileDTOs = null;
		int totalFile = 0;
		int totalImported = 0;		
		try {			
			if(sapComponentCornGrind.exists()){
				fileLines = sapComponentCornGrind.getContent();
				totalFile = fileLines.size();
				fileDTOs = sapComponentCornGrind.parse(fileLines);
				totalImported = sapComponentCornGrind.insertAll(fileDTOs);
				System.out.println("Summary-> total: " + totalFile + " ; imported : "+ totalImported);
			}
		} catch (SAPComponentFileException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}

	}

}
